import modbus_tk.modbus_tcp as mt
import modbus_tk.defines as md

#配置
modbus_connect = mt.TcpMaster("192.168.1.42",502)
modbus_connect.set_timeout(5.0)

modbus_connect43 = mt.TcpMaster("192.168.1.43",502)
modbus_connect43.set_timeout(5.0)

modbus_connect44 = mt.TcpMaster("192.168.1.44",502)
modbus_connect44.set_timeout(5.0)

modbus_connect45 = mt.TcpMaster("192.168.1.45",502)
modbus_connect45.set_timeout(5.0)

modbus_connect46 = mt.TcpMaster("192.168.1.46",502)
modbus_connect46.set_timeout(5.0)

modbus_connect47 = mt.TcpMaster("192.168.1.47",502)
modbus_connect47.set_timeout(5.0)

modbus_connect48 = mt.TcpMaster("192.168.1.48",502)
modbus_connect48.set_timeout(5.0)

modbus_connect49 = mt.TcpMaster("192.168.1.49",502)
modbus_connect49.set_timeout(5.0)
#读取数据
def data_read():
    data_all = modbus_connect.execute(1,md.READ_HOLDING_REGISTERS,0,3)
    data_all = list(data_all)
    print(data_all)
    return data_all
data_read()
# slave=1,function_code=md.READ_HOLDING_REGISTERS,starting_address=0,quantity_of_x=3,output_value=100